import LogFactory from "@/log/LogFactory.ts";
import {Button, Card, Descriptions, DescriptionsProps, Divider, Flex, Space} from "antd";
import {Link, useLocation} from "react-router-dom";
import RequestHandler from "@/http/RequestHandler.ts";
import {SecurityUser} from "@/type/SecurityUser";
import {useEffect, useState} from "react";
import {DeleteOutlined, MenuOutlined, UsergroupAddOutlined} from "@ant-design/icons";
import {userStatusToTag} from "@/component/admin/user/handler.tsx";

const log = LogFactory.getLogger("UserDetailComponent");
log.empty();
const UserDetailComponent = () => {
    const userId: number = useLocation().state.id;
    const [items, setItems] = useState<DescriptionsProps['items']>();

    useEffect(()=> {
        RequestHandler.get<SecurityUser>("/manager/admin/security_user/one/" + userId)
            .then(res => {
                const user_ = res.data
                const items_: DescriptionsProps['items'] = [
                    {
                        key: "id",
                        label: "用户编号",
                        children: user_.id
                    },
                    {
                        key: "username",
                        label: "用户名",
                        children: user_.username
                    },
                    {
                        key: "key",
                        label: "数据标识",
                        children: "KEY_" + user_.key.toUpperCase(),
                        span: 2
                    },
                    {
                        key: "password",
                        label: "用户密码",
                        children: user_.password,
                        span: 2
                    },
                    {
                        key: "identity",
                        label: "用户身份",
                        children: user_.identity
                    },
                    {
                        key: "avatar",
                        label: "用户头像",
                        children: user_.avatar
                    },
                    {
                        key: "enabled",
                        label: "用户启用",
                        children: userStatusToTag(user_.enabled)
                    },
                    {
                        key: "accountNonLocked",
                        label: "用户锁定",
                        children: userStatusToTag(user_.accountNonLocked)
                    },
                    {
                        key: "accountNonExpired",
                        label: "用户过期",
                        children: userStatusToTag(user_.accountNonExpired)
                    },
                    {
                        key: "credentialsNonExpired",
                        label: "密码过期",
                        children: userStatusToTag(user_.credentialsNonExpired)
                    },
                    {
                        key: "createTime",
                        label: "创建时间",
                        children: user_.createTime as string
                    },
                    {
                        key: "updateTime",
                        label: "更新时间",
                        children: user_.updateTime as string
                    },
                    {
                        key: "order",
                        label: "数据排序",
                        children: user_.order
                    },
                    {
                        key: "version",
                        label: "数据版本",
                        children: user_.version
                    },
                    {
                        key: "remark",
                        label: "备注信息",
                        children: user_.remark,
                        span: 2
                    }
                ];

                setItems(items_);
            })
    }, [])

    return (
        <Card title={"用户信息详情"} extra={<Link to={".."}>用户列表</Link>}>
            <Flex justify={"space-between"}>
                <Space size={20}>
                    <Button type={"primary"} icon={<UsergroupAddOutlined />}>用户角色分配</Button>
                    <Button type={"primary"} icon={<MenuOutlined />}>用户菜单分配</Button>
                </Space>
                <Button type={"primary"} danger icon={<DeleteOutlined />}>删除当前用户</Button>
            </Flex>
            <Divider/>
            <Descriptions
                bordered
                items={items}
                column={2}

                // items={user}
            >

            </Descriptions>
        </Card>
    );
};

export default UserDetailComponent;